package com.timk.goserver.client.ui.widgets;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/** */
public class ConfirmDialog extends CenteredDialog {
	/** Yes */
	public static final int CHOICE_YES = 0;
	/** No */
	public static final int CHOICE_NO = 1;
	
	int result; // NOPMD - Explicit scoping
	
	/**
	 * Creates a ConfirmationDialog
	 * @param parent panel to center dialog on
	 * @param title the title
	 * @param text the message to display
	 */
	public ConfirmDialog(UIObject parent, String title, String text) {
		super(parent);
		setText(title);
		
		VerticalPanel panel = new VerticalPanel();
		
		panel.add(new HTML(text));
		
		HorizontalPanel buttonPanel = new HorizontalPanel();
		
		Button yesButton = new Button("Yes");
		yesButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				result = CHOICE_YES;
				hide();
			}
		});
		buttonPanel.add(yesButton);
		
		Button noButton = new Button("No");
		noButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				result = CHOICE_NO;
				hide();
			}
		});
		buttonPanel.add(noButton);
		
		panel.add(buttonPanel);
		
		setWidget(panel);
	}
	
	/**
	 * Returns the result
	 * @return the result
	 */
	public int getResult() { return result; }
}
